package com.minyifang.wcspf.work.ui.user.activities;

import android.content.Intent;
import android.text.TextUtils;
import android.widget.EditText;

import com.minyifang.wcspf.R;
import com.minyifang.wcspf.common.base.BaseMvpActivity;
import com.minyifang.wcspf.common.utils.ToastHelper;
import com.minyifang.wcspf.work.model.HttpRespond;
import com.minyifang.wcspf.work.ui.user.presenter.ForgetPwdNextPresenter;
import com.minyifang.wcspf.work.ui.user.view.ForgetPwdNextView;

import butterknife.BindView;
import butterknife.BindViews;
import butterknife.OnClick;

/**
 * Created by LuoYaWei on 2018/6/14.
 */
public class ForgetPwdNextActivity extends BaseMvpActivity<ForgetPwdNextView, ForgetPwdNextPresenter> implements ForgetPwdNextView {

    @BindView(R.id.edt_pwd)
    EditText edt_pwd;
    @BindView(R.id.edt_pwd_confirm)
    EditText edt_pwd_confirm;

    private String phone;

    @Override
    protected ForgetPwdNextPresenter createPresenter() {
        return new ForgetPwdNextPresenter();
    }

    @Override
    protected int setContentLayoutRes() {
        return R.layout.activity_forget_pwd_next;
    }

    @Override
    protected void initView() {
        phone = getIntent().getStringExtra("phone");
    }

    @Override
    protected void initData() {

    }

    @OnClick(R.id.btn_confirm)
    void onConfirmClick() {
        String pwdStr = edt_pwd.getText().toString().trim();
        if (TextUtils.isEmpty(pwdStr)) {
            ToastHelper.getInstance(this).showWarn("请输入密码");
            return;
        }

        String pwdConfirmStr = edt_pwd_confirm.getText().toString().trim();
        if (TextUtils.isEmpty(pwdConfirmStr)) {
            ToastHelper.getInstance(this).showWarn("请再次输入密码");
            return;
        }

        if (!pwdStr.equals(pwdConfirmStr)) {
            ToastHelper.getInstance(this).showWarn("输入的密码请保持一致");
            return;
        }

        if (pwdStr.length() < 6) {
            ToastHelper.getInstance(this).showWarn("密码最少6位");
            return;
        }

        mPresenter.forgetPwd(phone, pwdStr, pwdConfirmStr);

    }

    @Override
    public void forgetPwdRes(HttpRespond respond) {
        if (respond.result == 1) {
            ToastHelper.getInstance(this).showSucceed(respond.message);
            startActivity(new Intent(this, LoginActivity.class));
            finish();
        } else
            ToastHelper.getInstance(this).showWarn(respond.message);
    }

    @OnClick(R.id.tv_service)
    void gotoService() {
        startActivity(new Intent(this, ServiceActivity.class));
    }

    @Override
    public void showLoadingView() {

    }

    @Override
    public void hideLoadingView() {

    }

    @Override
    public void onNetworkError() {

    }


}
